package airacrobats.gear;

import airacrobats.gui.container.SquadronSelectionContainer;
import airacrobats.game.Squadron;
import java.awt.GridBagConstraints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

/**
 * This gear handles the squadron selection.
 */
public class SquadronGear extends Gear implements ActionListener
{
    /**
     * Squadron selection container.
     */
    private SquadronSelectionContainer squadronSelectionContainer;

    /**
     * The gear listener.
     */
    public SquadronGear(GearListener gearListener)
    {
        super(gearListener);
    }

    /**
     */
    public void load()
    {
        List<Squadron> squadrons = new ArrayList<Squadron>();
        for (Squadron.Type squadronType : Squadron.Type.values())
        {
            Squadron squadron = new Squadron(squadronType,
                    imageLoader.get(squadronType.getMapKey() + "/Preview.png"),
                    squadronLoader.get(squadronType.getMapKey() + "/Squadron.dat"));
            squadrons.add(squadron);
        }

        squadronSelectionContainer = new SquadronSelectionContainer(this, squadrons);

        GridBagConstraints c = new GridBagConstraints();

        c.gridx = 0;
        c.gridy = 0;
        add(squadronSelectionContainer, c);
    }

    /**
     */
    public void actionPerformed(ActionEvent e)
    {
        if (e.getSource() == squadronSelectionContainer.getButton())
        {
            Gear gear = new SplashGear(this.gearListener, new MenuGear(this.gearListener,
                    squadronSelectionContainer.getSelectedSquadron()),
                    squadronSelectionContainer.getSelectedSquadron());
            gear.load();
            gearListener.gearChanging(gear);
        }
    }
}
